#include <stdio.h>
#include <errno.h>
#include <string.h>

#define FOPEN_ERR(FP) if (NULL == FP) \
    { \
    perror("fopen error:"); \
    return 0; \
    } \

int main(int argc, char const *argv[])
{
    if (3 != argc)
    {
        printf("格式错误 : %s file_dest file_src\n",argv[0]);
        return 0;
    }
        
    //打开文件
    FILE *fp_dest = fopen(argv[1] , "w+");
    FOPEN_ERR(fp_dest);
    FILE *fp_src = fopen(argv[2],"r+");
    FOPEN_ERR(fp_src);
    
    //移动到文件头部

    fseek( fp_dest , 0 ,SEEK_SET);
    fseek( fp_src , 0 ,SEEK_SET);

    char buf[1024];

    memset(buf , 0 ,sizeof(buf));

    int byte = 0;
    while ((byte = fread(buf , 1 ,sizeof(buf),fp_src)) > 0)
    {
        fwrite(buf , 1 ,byte ,fp_dest);
    }
    
    fclose(fp_dest);
    fclose(fp_src);
    
    return 0;
}
